package com.baize.baizeapp.test.chat

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import com.farsunset.cim.sdk.android.CIMPushManager

class CIMPushManagerReceiver : BroadcastReceiver() {

    override fun onReceive(context: Context?, intent: Intent?) {
        when (intent?.action) {
            "android.net.conn.CONNECTIVITY_CHANGE", "com.farsunset.cim.NETWORK_CHANGED" -> {
                Log.i("yanze_chat", "网络变事件action:")
            }
            "com.farsunset.cim.MESSAGE_RECEIVED" -> {
                Log.i("yanze_chat", "收到消息事件action:")
            }
            "com.farsunset.cim.SEND_FINISHED" -> {
                Log.i("yanze_chat", "·:")
            }
            "com.farsunset.cim.CONNECTION_RECOVERY" -> {
                Log.i("yanze_chat", "重新连接事件action:")
            }
            "com.farsunset.cim.CONNECTION_CLOSED" -> {
                Log.i("yanze_chat", "连接关闭事件action:")
            }
            "com.farsunset.cim.CONNECT_FAILED" -> {
                Log.i("yanze_chat", "连接失败事件action:${intent.data}${intent.dataString}")
            }
            "com.farsunset.cim.CONNECT_FINISHED" -> {
                Log.i("yanze_chat", "连接成功事件action:")
                /*
                 * 第二步 绑定用户id到长连接
                 * 这里业务方可以设置token等由后端实现转换成用户id
                 */
                CIMPushManager.bind(context, 10000)
            }
            "com.farsunset.cim.REPLY_RECEIVED" -> {
                Log.i("yanze_chat", "收到replyBody事件action:")
            }
        }
    }

}